package leetcode;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

/**
 * ClassName: BaiduT3
 * Package: leetcode
 * Description:
 *
 * @Author wjn
 * @Create 2025/9/2 19:45
 * @Version 1.0
 */
public class BaiduT3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = scanner.nextInt();
        while (T-- > 0) {
            int n = scanner.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = scanner.nextInt();
            }
            for (int i = 0; i < n; i++) {
                b[i] = scanner.nextInt();
            }
            Set<Integer> OrSet = new HashSet<>();
            OrSet.add(0);
            boolean flag = true;
            for (int i = 0; i < n; i++){
                Set<Integer> newOrSet = new HashSet<>(OrSet);
                for (int num : OrSet) {
                    newOrSet.add(num | a[i]);
                }
                OrSet = newOrSet;
                if (!OrSet.contains(b[i])) {
                    flag = false;
                    break;
                }
            }
            System.out.println(flag ? "Yes" : "No");
        }
        scanner.close();
    }
}
